/**
 * 
 */
package com.jie.eclipse.pan.listener;

import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.widgets.Scrollable;
import org.eclipse.swt.widgets.Widget;

import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.editors.form.PllDetailPage;
import com.jie.eclipse.pan.utils.handle.FileHandle;

/**
 * @author yanjie
 *
 */
public class PFocusListener implements FocusListener {
	public static final String TAG_PLLEDIT_LISTENER = "PLLEDIT_LISTENER";//保存xml
	private String type = "";
	private FileHandle fileHandle = null; 
	protected BaseDataEntity data = null;
	/**
	 * 
	 */
	public PFocusListener(BaseDataEntity data) {
		this.data = data;
	}
	/**
	 * 
	 */
	public PFocusListener(String type, FileHandle fileHandle) {
		this.type = type;
		this.fileHandle = fileHandle;
	}
	
	public void focusLost(FocusEvent paramFocusEvent) {
		if(TAG_PLLEDIT_LISTENER.equalsIgnoreCase(type)){
			Object obj = paramFocusEvent.getSource();
			if(obj instanceof Scrollable){
				Scrollable source = (Scrollable)obj;
				if(source.getData("change") != null && (Boolean)source.getData("change")){
					source.setData("change", null);
					this.fileHandle.modelToXml();
				}
			}
			
		}
	}
	
	public void focusGained(FocusEvent paramFocusEvent) {
//		Widget source = (Widget)paramFocusEvent.getSource();
	}
	
	public static PFocusListener getPFocusListener(PllDetailPage detailPage){
		return new PFocusListener(PFocusListener.TAG_PLLEDIT_LISTENER,detailPage.getFileHandle());
	}
}
